//
//  SNBaseLabel.m
//  project
//
//  Created by 黄建华 on 2018/6/26.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNBaseLabel.h"

@implementation SNBaseLabel

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _label.numberOfLines = 0;
        _label.lineBreakMode = NSLineBreakByWordWrapping;
        [self addSubview:_label];
    }
    return self;
}

// 重设标签的高
- (void)setText:(NSString *)text
{
    _label.text = text;
    CGSize size = [_label sizeThatFits:CGSizeMake(_label.frame.size.width, MAXFLOAT)];
    _label.frame  = CGRectMake(_label.frame.origin.x, _label.frame.origin.y, _label.frame.size.width, size.height);
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width,size.height);
}


@end
